package ext.tianma.part.AVLMaterial.service;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import wt.fc.PersistenceHelper;
import wt.fc.collections.WTHashSet;
import wt.part.WTPartMaster;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
import ext.tianma.model.APLQuantity;
import ext.tianma.part.AVLMaterial.AVLUtil;

public class APLQuantityService {

	/**
	 * 修改当前APL材料用量表中为流程/非流程中
	 * @param part
	 * @author xucr
	 * @throws JSONException 
	 * @CreateDate 2020年11月11日
	 */
	public static void updateAPLQuantity(WTPartMaster part, String[] ranges, boolean isProcess, boolean isPromotion) throws JSONException {
		JSONObject obj = new JSONObject();
		obj.put("aplPartNumber", part.getNumber());
		WTHashSet set = new WTHashSet();
		List<APLQuantity> quantitys = AVLUtil.getAPLQuantitys(part.getPersistInfo().getObjectIdentifier().getId(), ranges);
		try {
			if(null != quantitys && quantitys.size() > 0) {
				for(APLQuantity quantity : quantitys) {
					quantity.setProcesses(isProcess);
					quantity.setPromotion(isPromotion);
					set.add(quantity);
				}
				if(set.size() > 0) {
					PersistenceHelper.manager.save(set);
				}
			}
		} catch (WTPropertyVetoException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
	}
}
